package co.com.claro.comun.util;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Manuel Serrano
 * Date: 29/07/13
 * Time: 06:07 PM
 * To change this template use File | Settings | File Templates.
 */
public class util {


    public static List<String> getTabTable (Class c){


        Class clase = c;
        Method[] atributos = clase.getMethods();
        List<String> tabMenu=new ArrayList<String>();
        for (Method dato : atributos){

            if((dato.getName().indexOf("get")!=-1)&&(dato.getName().indexOf("$")!=-1)&&(isNumeric(dato.getName().substring(dato.getName().length()-1,dato.getName().length())))){
                tabMenu.add(dato.getName().substring(3,dato.getName().length()));
            }
        }

        tabMenu=ordenar(tabMenu);



    return tabMenu;
    }


    public static List<String> ordenar(List<String> list)
    {
        ArrayList<String> theReturn = new ArrayList<String>(list.size());

        for (int i = 0; i < list.size(); i++) {
            theReturn.add("");
        }

        for( int i = 0 ; i < list.size(); i++){
            theReturn.set((Integer.parseInt(list.get(i).substring(list.get(i).length()-2,list.get(i).length()))-1),(list.get(i).substring(0,list.get(i).length()-3)));
        }

        return theReturn;
    }




    private static boolean isNumeric(String cadena){
        try {
            Integer.parseInt(cadena);
            return true;
        } catch (NumberFormatException nfe){
            return false;
        }
    }
}
